<template>
  <div>
    <ky-table
      :getData="getconfigChangeLog"
      :search_data="search_data"
      :search_criteria="search_criteria"
    >
      <template v-slot:table>
        <el-table-column prop="name" :label="$t('configure.configure_name')">
        </el-table-column>
        <el-table-column
          prop="baseline"
          :label="$t('configure.configure_value_old')"
        >
        </el-table-column>
        <el-table-column
          prop="curBaseline"
          :label="$t('configure.configure_value_new')"
        >
        </el-table-column>
        <el-table-column
          prop="createdAt"
          :label="$t('configure.change_time')"
        >
        </el-table-column>
        <el-table-column prop="filePath" :label="$t('configure.file_path')">
        </el-table-column>
      </template>
    </ky-table>
  </div>
</template>

<script>
import kyTable from "@/components/KyTable";
import {getconfigChangeLog} from "@/api/host_detail";
import {getClassInfo} from "@/api/config";
export default {
  components: {
    kyTable,
  },
  data() {
    return {
      search_data: {
          name: {
              name: "configure.configure_name",
              type: "text"
          },
          baseline: {
              name: "configure.configure_value_old",
              type: "text"
          },
          curBaseline: {
              name: "configure.configure_value_new",
              type: "text"
          },
          createdAt: {
              name: 'configure.change_time',
              type: "date"
          },
          filePath: {
              name: "configure.file_path",
              type: "select",
              items: [],
              func: this.getConfigureInfo
          }
      },
      search_criteria: {
          hostId: this.$route.params.id
      }
    };
  },
  methods: {
      getconfigChangeLog,
      getConfigureInfo() {
          getClassInfo().then(res => {
              let data = res.data.data;
              let configTypes = Object.keys(data);
              let files = [];
              configTypes.forEach(key => {
                  data[key].forEach(item => {
                      for (let k in item) {
                          const index = files.indexOf(item[k]);
                          if (index < 0) {
                              files.push(item[k]);
                              this.search_data["filePath"].items.push({key: item[k], name: item[k]})
                          }
                      }
                  })
              })
          })
      }
  }
};
</script>

<style>
</style>